# -*- coding:utf-8 -*-
import datetime
from service.total_analyse import final_analyse
__author__ = 'shudongma.msd(风骐)'


"""
跑程序 记录：
2016-01-03 ~ 2016-02-20 ：
gb
    is_selected_feature=False,is_pca=False   cross-valiate 0.605082319256    valiate
    is_selected_feature=True,is_pca=False    cross-valiate 0.605917442138   valiate
    is_selected_feature=True,is_pca=True    cross-valiate 0.50346774835   valiate  0.85


filter [ 0.5731394   0.53976047  0.42059377  0.68090671  0.65741293] 0.574362656455
nofilter [ 0.53352422  0.53666587  0.53793844  0.72222222  0.69923646] 0.605917442138

svm
    is_selected_feature=False,is_pca=False   cross-valiate    valiate
    is_selected_feature=True,is_pca=False    cross-valiate    valiate
    is_selected_feature=True,is_pca=True     cross-valiate  [ 0.42623868  0.42877595  0.55609243]   valiate 0.6

2015-10-08 ~ 2016-02-20     ：
is_selected_feature=True,is_pca=False     cross-valiate             valiate   0.86
is_selected_feature=True,is_pca=True      cross-valiate   0.4          valiate
"""

if __name__ == '__main__':
    # 时间区间选择
    # start_date = datetime.datetime.strptime('2015-10-08', "%Y-%m-%d").date()
    start_date = datetime.datetime.strptime('2015-11-01', "%Y-%m-%d").date()
    # start_date = datetime.datetime.strptime('2016-01-03', "%Y-%m-%d").date()
    # start_date = datetime.datetime.strptime('2016-03-01', "%Y-%m-%d").date()
    # end_date = datetime.datetime.strptime('2015-10-10', "%Y-%m-%d").date()
    # end_date = datetime.datetime.strptime('2015-12-30', "%Y-%m-%d").date()    # gb
    # end_date = datetime.datetime.strptime('2016-01-31', "%Y-%m-%d").date()    # gb
    # end_date = datetime.datetime.strptime('2016-03-21', "%Y-%m-%d").date()    # gb
    end_date = datetime.datetime.strptime('2016-04-01', "%Y-%m-%d").date()


    is_selected_feat = True
    is_pca = False
    alg = 'gb'
    classfy = 'tend'
    ta = final_analyse.Thesis_Analyse(start_date,end_date,meathod='drop',classfied=classfy,
                        is_selected_feature=is_selected_feat,is_pca=is_pca,pca_n_components=1,
                        algorithm=alg,filtGabageDate=False)

    # 优化算法参数
    # ta.optim_alg_param_test(test_size=0.2,label_type='0-1')

    # 排选特征变量
    # ta.selectFea(label_type='0-1')
    # ta.selectFeaByModel()

    # pca
    # ta.draw_pca_score(label_type='0-1',white=False)

    # 验证模型
    # ta.validate_model(test_size=0.2,label_type='0-1')
    # ta.cross_validate_model(cv=5,label_type='0-1')

    # ta.validate_model(test_size=0.2,label_type='0-1')

    # 训练实际模型
    # ta.train_model(label_type='0-1')

    # 保存模型
    # final_analyse.storeAlg(ta,alg+'#'+str(start_date)+'#'+str(end_date)+'#'+str(is_selected_feat)+'#'+str(is_pca)+'#'+str(classfy)+'.pkl')

    # 预测
    # ta = final_analyse.grapAlg(alg+'#'+str(start_date)+'#'+str(end_date)+'#'+str(is_selected_feat)+'#'+str(is_pca)+'#'+str(classfy)+'.pkl')
    # pred_dict = ta.predict_next_trade_day('2016-03-14')
    # print pred_dict
    # print ta.getTrendByStockId(pred_dict,'SZ002237')

    # 检验下一个交易日波动
    # print "2016-03-23"
    # ta.validate_next_trade('2016-03-23')
    # print "2016-03-24"
    # ta.validate_next_trade('2016-03-24')
    # print "2016-03-25"
    # ta.validate_next_trade('2016-03-25')
    # print "2016-03-28"
    # ta.validate_next_trade('2016-03-28')
    # print "2016-03-29"
    # ta.validate_next_trade('2016-03-29')
    # print "2016-03-30"
    # ta.validate_next_trade('2016-03-30')
    # print "2016-03-31"
    # ta.validate_next_trade('2016-03-31')
    # print "2016-04-01"
    # ta.validate_next_trade('2016-04-01')
    # print "2016-04-04"
    # ta.validate_next_trade('2016-04-04')
    # print "2016-04-05"
    # ta.validate_next_trade('2016-04-05')
    # print "2016-04-06"
    # ta.validate_next_trade('2016-04-06')
    # print "2016-04-07"
    # ta.validate_next_trade('2016-04-07')
    # print "2016-04-08"
    # ta.validate_next_trade('2016-04-08')
    # print "2016-04-11"
    # ta.validate_next_trade('2016-04-11')


    # 导出数据
    # ta.export_csv()

    ta.desc_model(test_size=0.2,label_type='0-1')


